package com.isoft.controller.sys;


import com.isoft.bean.ResponseData;
import com.isoft.controller.BaseController;
import com.isoft.entity.BeginTime;
import com.isoft.entity.Endplace;
import com.isoft.entity.FlightLine;
import com.isoft.service.impl.FlightLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
    @RequestMapping("/sys/flightline")
public class FlightLineController extends BaseController {

    @Autowired
    FlightLineService flightLineService;

    //获取已经通过审核的所有航班
    @GetMapping("/gets")
    public ResponseData<Object> selectAllLine(int currentPage, int size) {
        return returnObject(flightLineService.selectAllLinePage(currentPage,size));
    }

    //获取未审核的航班
    @GetMapping("/gets2")
    public ResponseData<Object> selectUnPublicLine(int currentPage, int size) {
        return returnObject(flightLineService.selectUnPublicLinePage(currentPage,size));
    }

    //根据开始时间、结束时间、目的地，查询已经发布的航班信息
    @GetMapping("/getsbycon")
    public ResponseData<Object> selectByCondition(Integer currentPage, Integer size,String starttime, String city) {
        return returnObject(flightLineService.selectByConPage(currentPage,size,starttime,city));
    }

    //根据日期查询航班
    @GetMapping("/getbyday")
    public ResponseData<Object> selectByDay(String day) {
        return returnObject(flightLineService.selectByDay(day));
    }

    //添加航班，等待管理员审核
    @PostMapping("/add")
    public ResponseData<Boolean> addLine(FlightLine flightLine) {
        return returnBoolean(flightLineService.addLine(flightLine));
    }

    //删除航班信息，做物理删除
    @DeleteMapping("/delete")
    public ResponseData<Boolean> deleteLine(Integer id) {
        return returnBoolean(flightLineService.deleteLine(id));
    }

    //更新航班信息
    @PutMapping("/update")
    public ResponseData<Boolean> updateLine(FlightLine flightLine) {
        return returnBoolean(flightLineService.updateLine(flightLine));
    }

    //审核管理员审核，通过则正式发布航班
    @PutMapping("/permit")
    public ResponseData<Boolean> publicLine(Integer id) {
        return returnBoolean(flightLineService.passPermit(id));
    }

    //查询航班目的地排名前六的目的地名和到达次数
    @GetMapping("/endplace")
    public List<Endplace> selectByEndplace(){
        return  flightLineService.selectByEndplace();
    }
    @GetMapping("/begintime")
    public List<BeginTime> selectByBeginTime(){
        return  flightLineService.selectByBeginTime();
    }

}
